/**
 * @project sso-token-start V1.0
 * @Title:  Result.java  
 * @Package com.gitee.kinbug.sso.model 
 * Copyright(c) 2020 KinBug Co. Ltd. 
 * All right reserved. 
 */
package com.gitee.kinbug.sso.model;

import java.io.Serializable;

import com.alibaba.fastjson.JSON;

/**   
 * Description:TODO(返回结果)   
 * @author: KinBug
 */
public class Result<T> implements Serializable {
	public static final long serialVersionUID = 42L;

	public static final int SUCCESS_CODE = 200;
	public static final int FAIL_CODE = 500;
	public static final Result<String> SUCCESS = new Result<String>(null);
	public static final Result<String> FAIL = new Result<String>(FAIL_CODE, null, null);

	private int code;
	private String msg;
	private T data;

	public Result(int code, String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Result success(String msg, Object data) {
		return new Result(SUCCESS_CODE, msg, data);
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Result error(String msg, Object data) {
		return new Result(FAIL_CODE, msg, data);
	}

	public Result(T data) {
		this.code = SUCCESS_CODE;
		this.data = data;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String toJsonString() {
	    	return JSON.toJSONString(this);
	}

}
